package com.fsk.user.controller;

import com.fsk.init.dao.mybatisPojo.user;
import com.fsk.init.dao.mybatisPojo.userExample;
import com.fsk.user.dao.mapper.userMapper;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.DiscoveryClient;
import org.apache.catalina.util.ServerInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/userInfo")
public class UserInfo {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Resource
    private userMapper userMapper;

    @GetMapping("/getUserById")
    public user getUserInfoById(@Param(value = "id") Integer id) {
        user result = new user();
        userExample userExample = new userExample();
        userExample.createCriteria().andIdEqualTo(id);
        List<user> users = userMapper.selectByExample(userExample);
        if (users.isEmpty()) {
            return null;
        }
        result = users.get(0);
        return result;
    }

    @GetMapping("/getTestInitInstance")
    public List<InstanceInfo> getUserInfoById() {
        return discoveryClient.getInstancesById("microservice-testinit");
    }
}
